package NG::Gen::Users;
use strict;
use warnings;
use utf8;

use Extend;
use NG::Sys::Cfg;

use base 'NG::Sys::Cached::Mixed';
use NG::Sys::Spec::BlockerInterface;

sub new {
    my ($class,%args) = @_;
	my $app = $args{app};

	my $tune = config("users");
	$args{cache} = $app->get_cache(%{$tune->{cache}});
	$args{tables} = $tune->{tables};
	$args{extern} = $tune->{extern};
	my @kp = keys %{$tune->{param}};
	@args{@kp} = @{$tune->{param}}{@kp};
	my $self = Class->SUPER::new(%args);
	$self->{user_config} = config("user");
	NG::Sys::Spec::BlockerInterface::attach(ref $self,$self->{record_class},$app->local_block,$tune->{param}{namespace});
	return $self;
}
sub init {
	my ($self) = @_;
	$self->SUPER::init;
}
sub get_by_id {
	my $self = shift;
	return $self->get_obj(@_);
}
sub get_by_login {
	my $self = shift;
	return $self->get_by_name(@_);
}
sub remove_user {
	my ($self,$user_id) = @_;
	my $oUser = $self->get_obj($user_id);
	$oUser->before_remove;
	$self->{record_class}->remove_user($self,$oUser);
	$oUser->remove;
}
sub create_user {
	my ($self) = @_;
	my $user = $self->{record_class}->create_user(@_);
	my $oUser = $self->create(0,$user);
	if($oUser){
		if(my $err = $oUser->after_create){
			$self->{record_class}->remove_user($self,$oUser);
			$oUser->remove;
			return $err;
		}
	}
	return $oUser;
	
}
sub check_login {
	my $self = shift;
	return $self->check_for_name(@_);
}


1;
